<template>
    <!-- 基于 Element UI 新增和修改弹窗 -->
    <el-dialog :title="!dataForm.id ? '添加-ADD' : '修改-EDITE'" :close-on-click-modal="false" :visible.sync="visible">
        <!-- 新增和创建表单表单 -->
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataSubmit()"
            label-width="80px">
            <el-form-item label="关联eb_benefit_activity表id" prop="activityId">
                <el-input v-model="dataForm.activityId" placeholder="关联eb_benefit_activity表id"></el-input>
            </el-form-item>
            <el-form-item label="用户ID" prop="uid">
                <el-input v-model="dataForm.uid" placeholder="用户ID"></el-input>
            </el-form-item>
            <el-form-item label="代理商ID" prop="aid">
                <el-input v-model="dataForm.aid" placeholder="代理商ID"></el-input>
            </el-form-item>
            <el-form-item label="捐赠数量" prop="donateNum">
                <el-input v-model="dataForm.donateNum" placeholder="捐赠数量"></el-input>
            </el-form-item>
            <el-form-item label="创建时间" prop="createTime">
                <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">取消</el-button>
            <el-button type="primary" @click="dataSubmit()">确定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import * as api from '@/api/benefitActivityRecord.js'
export default {
    data() {
        return {
            visible: false,
            dataForm: {
                id: 0,
                activityId: '',
                uid: '',
                aid: '',
                donateNum: '',
                createTime: ''
            },
            dataRule: {
                activityId: [
                    { required: true, message: '关联eb_benefit_activity表id  为必填项', trigger: 'blur' }
                ],
                uid: [
                    { required: true, message: '用户ID  为必填项', trigger: 'blur' }
                ],
                aid: [
                    { required: true, message: '代理商ID  为必填项', trigger: 'blur' }
                ],
                donateNum: [
                    { required: true, message: '捐赠数量  为必填项', trigger: 'blur' }
                ],
                createTime: [
                    { required: true, message: '创建时间  为必填项', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        init(id) { // 初始化表单验证规则
            this.dataForm.id = id || 0
            this.visible = true
            this.$nextTick(() => {
                this.$refs['dataForm'].resetFields()
                if (this.dataForm.id) {
                    api.benefitactivityrecordDetailApi(id).then(res => {
                        this.dataForm = res;
                    })
                }
            })
        },
        // 表单数据提交
        dataSubmit() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    api.BenefitActivityRecordCreateApi().then(res => {
                        // TODO 保存数据
                    });
                }
            })
        }
    }
}
</script>